Paho Asynchronous MQTT C Client Library
Loading...
Searching...
No Matches
MQTTAsync.h
Go to the documentation of this file.
1/*******************************************************************************
2 * Copyright (c) 2009, 2018 IBM Corp.
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * and Eclipse Distribution License v1.0 which accompany this distribution.
7 *
8 * The Eclipse Public License is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 * and the Eclipse Distribution License is available at
11 * http://www.eclipse.org/org/documents/edl-v10.php.
12 *
13 * Contributors:
14 * Ian Craggs - initial API and implementation
15 * Ian Craggs, Allan Stockdill-Mander - SSL connections
16 * Ian Craggs - multiple server connection support
17 * Ian Craggs - MQTT 3.1.1 support
18 * Ian Craggs - fix for bug 444103 - success/failure callbacks not invoked
19 * Ian Craggs - automatic reconnect and offline buffering (send while disconnected)
20 * Ian Craggs - binary will message
21 * Ian Craggs - binary password
22 * Ian Craggs - remove const on eyecatchers #168
23 *******************************************************************************/
24
25/********************************************************************/
26
85/*
87*/
88#if defined(__cplusplus)
89 extern "C" {
90#endif
91
92#if !defined(MQTTASYNC_H)
93#define MQTTASYNC_H
94
95#if defined(WIN32) || defined(WIN64)
96 #define DLLImport __declspec(dllimport)
97 #define DLLExport __declspec(dllexport)
98#else
99 #define DLLImport extern
100 #define DLLExport __attribute__ ((visibility ("default")))
101#endif
102
103#include <stdio.h>
104/*
106*/
107
108#if !defined(NO_PERSISTENCE)
110#endif
111
116#define MQTTASYNC_SUCCESS 0
121#define MQTTASYNC_FAILURE -1
122
123/* error code -2 is MQTTAsync_PERSISTENCE_ERROR */
124
125#define MQTTASYNC_PERSISTENCE_ERROR -2
126
130#define MQTTASYNC_DISCONNECTED -3
135#define MQTTASYNC_MAX_MESSAGES_INFLIGHT -4
139#define MQTTASYNC_BAD_UTF8_STRING -5
143#define MQTTASYNC_NULL_PARAMETER -6
149#define MQTTASYNC_TOPICNAME_TRUNCATED -7
154#define MQTTASYNC_BAD_STRUCTURE -8
158#define MQTTASYNC_BAD_QOS -9
162#define MQTTASYNC_NO_MORE_MSGIDS -10
166#define MQTTASYNC_OPERATION_INCOMPLETE -11
170#define MQTTASYNC_MAX_BUFFERED_MESSAGES -12
174#define MQTTASYNC_SSL_NOT_SUPPORTED -13
178#define MQTTASYNC_BAD_PROTOCOL -14
179
180
184#define MQTTVERSION_DEFAULT 0
188#define MQTTVERSION_3_1 3
192#define MQTTVERSION_3_1_1 4
196#define MQTT_BAD_SUBSCRIBE 0x80
197
198
202typedef struct
203{
205 char struct_id[4];
211
212#define MQTTAsync_init_options_initializer { {'M', 'Q', 'T', 'G'}, 0, 0 }
213
219
224typedef void* MQTTAsync;
234typedef int MQTTAsync_token;
235
242typedef struct
243{
245 char struct_id[4];
251 void* payload;
265 int qos;
291 int dup;
295 int msgid;
297
298#define MQTTAsync_message_initializer { {'M', 'Q', 'T', 'M'}, 0, 0, NULL, 0, 0, 0, 0 }
299
326typedef int MQTTAsync_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync_message* message);
327
346typedef void MQTTAsync_deliveryComplete(void* context, MQTTAsync_token token);
347
363typedef void MQTTAsync_connectionLost(void* context, char* cause);
364
365
378typedef void MQTTAsync_connected(void* context, char* cause);
379
380
381
383typedef struct
384{
388 int code;
390 const char *message;
392
394typedef struct
395{
399 union
400 {
402 int qos;
406 struct
407 {
410 } pub;
411 /* For connect, the server connected to, MQTT version used, and sessionPresent flag */
412 struct
413 {
417 } connect;
418 } alt;
420
431typedef void MQTTAsync_onSuccess(void* context, MQTTAsync_successData* response);
432
443typedef void MQTTAsync_onFailure(void* context, MQTTAsync_failureData* response);
444
445typedef struct
446{
448 char struct_id[4];
468 void* context;
476
477#define MQTTAsync_responseOptions_initializer { {'M', 'Q', 'T', 'R'}, 0, NULL, NULL, 0, 0 }
478
479
508DLLExport int MQTTAsync_setCallbacks(MQTTAsync handle, void* context, MQTTAsync_connectionLost* cl,
510
511
524DLLExport int MQTTAsync_setConnected(MQTTAsync handle, void* context, MQTTAsync_connected* co);
525
526
535DLLExport int MQTTAsync_reconnect(MQTTAsync handle);
536
537
579DLLExport int MQTTAsync_create(MQTTAsync* handle, const char* serverURI, const char* clientId,
580 int persistence_type, void* persistence_context);
581
582typedef struct
583{
585 char struct_id[4];
593
594#define MQTTAsync_createOptions_initializer { {'M', 'Q', 'C', 'O'}, 0, 0, 100 }
595
596
597DLLExport int MQTTAsync_createWithOptions(MQTTAsync* handle, const char* serverURI, const char* clientId,
598 int persistence_type, void* persistence_context, MQTTAsync_createOptions* options);
599
612typedef struct
613{
615 char struct_id[4];
621 const char* topicName;
623 const char* message;
632 int qos;
634 struct
635 {
636 int len;
637 const void* data;
638 } payload;
640
641#define MQTTAsync_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 1, NULL, NULL, 0, 0, { 0, NULL } }
642
643#define MQTT_SSL_VERSION_DEFAULT 0
644#define MQTT_SSL_VERSION_TLS_1_0 1
645#define MQTT_SSL_VERSION_TLS_1_1 2
646#define MQTT_SSL_VERSION_TLS_1_2 3
647
660typedef struct
661{
663 char struct_id[4];
666
668 const char* trustStore;
669
673 const char* keyStore;
674
678 const char* privateKey;
681
691
694
700
707
713 const char* CApath;
715
716#define MQTTAsync_SSLOptions_initializer { {'M', 'Q', 'T', 'S'}, 2, NULL, NULL, NULL, NULL, NULL, 1, MQTT_SSL_VERSION_DEFAULT, 0, NULL }
717
723typedef struct
724{
726 char struct_id[4];
783 const char* username;
789 const char* password;
820 void* context;
833 char* const* serverURIs;
856 struct {
857 int len;
858 const void* data;
859 } binarypwd;
861
862
863#define MQTTAsync_connectOptions_initializer { {'M', 'Q', 'T', 'C'}, 5, 60, 1, 10, NULL, NULL, NULL, 30, 0,\
864NULL, NULL, NULL, NULL, 0, NULL, 0, 0, 1, 60, {0, NULL}}
865
886DLLExport int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options);
887
888
889typedef struct
890{
892 char struct_id[4];
917 void* context;
919
920#define MQTTAsync_disconnectOptions_initializer { {'M', 'Q', 'T', 'D'}, 0, 0, NULL, NULL, NULL }
921
922
941DLLExport int MQTTAsync_disconnect(MQTTAsync handle, const MQTTAsync_disconnectOptions* options);
942
943
951DLLExport int MQTTAsync_isConnected(MQTTAsync handle);
952
953
968DLLExport int MQTTAsync_subscribe(MQTTAsync handle, const char* topic, int qos, MQTTAsync_responseOptions* response);
969
970
988DLLExport int MQTTAsync_subscribeMany(MQTTAsync handle, int count, char* const* topic, int* qos, MQTTAsync_responseOptions* response);
989
1002DLLExport int MQTTAsync_unsubscribe(MQTTAsync handle, const char* topic, MQTTAsync_responseOptions* response);
1003
1016DLLExport int MQTTAsync_unsubscribeMany(MQTTAsync handle, int count, char* const* topic, MQTTAsync_responseOptions* response);
1017
1018
1037DLLExport int MQTTAsync_send(MQTTAsync handle, const char* destinationName, int payloadlen, void* payload, int qos, int retained,
1038 MQTTAsync_responseOptions* response);
1039
1040
1056DLLExport int MQTTAsync_sendMessage(MQTTAsync handle, const char* destinationName, const MQTTAsync_message* msg, MQTTAsync_responseOptions* response);
1057
1058
1078
1087#define MQTTASYNC_TRUE 1
1089
1090
1101DLLExport int MQTTAsync_waitForCompletion(MQTTAsync handle, MQTTAsync_token token, unsigned long timeout);
1102
1103
1115
1124DLLExport void MQTTAsync_free(void* ptr);
1125
1133DLLExport void MQTTAsync_destroy(MQTTAsync* handle);
1134
1135
1136
1138{
1146};
1147
1148
1155
1156
1165typedef void MQTTAsync_traceCallback(enum MQTTASYNC_TRACE_LEVELS level, char* message);
1166
1174
1175
1176typedef struct
1177{
1178 const char* name;
1179 const char* value;
1181
1189
1190
1747#endif
1748
1749#ifdef __cplusplus
1750 }
1751#endif
DLLExport int MQTTAsync_setCallbacks(MQTTAsync handle, void *context, MQTTAsync_connectionLost *cl, MQTTAsync_messageArrived *ma, MQTTAsync_deliveryComplete *dc)
DLLExport int MQTTAsync_send(MQTTAsync handle, const char *destinationName, int payloadlen, void *payload, int qos, int retained, MQTTAsync_responseOptions *response)
DLLExport int MQTTAsync_createWithOptions(MQTTAsync *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context, MQTTAsync_createOptions *options)
void * MQTTAsync
Definition: MQTTAsync.h:224
DLLExport int MQTTAsync_disconnect(MQTTAsync handle, const MQTTAsync_disconnectOptions *options)
void MQTTAsync_connected(void *context, char *cause)
Definition: MQTTAsync.h:378
DLLExport int MQTTAsync_isComplete(MQTTAsync handle, MQTTAsync_token token)
void MQTTAsync_connectionLost(void *context, char *cause)
Definition: MQTTAsync.h:363
int MQTTAsync_messageArrived(void *context, char *topicName, int topicLen, MQTTAsync_message *message)
Definition: MQTTAsync.h:326
DLLExport void MQTTAsync_global_init(MQTTAsync_init_options *inits)
DLLExport int MQTTAsync_getPendingTokens(MQTTAsync handle, MQTTAsync_token **tokens)
DLLExport int MQTTAsync_create(MQTTAsync *handle, const char *serverURI, const char *clientId, int persistence_type, void *persistence_context)
DLLExport int MQTTAsync_reconnect(MQTTAsync handle)
MQTTASYNC_TRACE_LEVELS
Definition: MQTTAsync.h:1138
@ MQTTASYNC_TRACE_FATAL
Definition: MQTTAsync.h:1145
@ MQTTASYNC_TRACE_MEDIUM
Definition: MQTTAsync.h:1140
@ MQTTASYNC_TRACE_SEVERE
Definition: MQTTAsync.h:1144
@ MQTTASYNC_TRACE_PROTOCOL
Definition: MQTTAsync.h:1142
@ MQTTASYNC_TRACE_MINIMUM
Definition: MQTTAsync.h:1141
@ MQTTASYNC_TRACE_ERROR
Definition: MQTTAsync.h:1143
@ MQTTASYNC_TRACE_MAXIMUM
Definition: MQTTAsync.h:1139
void MQTTAsync_onFailure(void *context, MQTTAsync_failureData *response)
Definition: MQTTAsync.h:443
void MQTTAsync_traceCallback(enum MQTTASYNC_TRACE_LEVELS level, char *message)
Definition: MQTTAsync.h:1165
DLLExport void MQTTAsync_freeMessage(MQTTAsync_message **msg)
DLLExport int MQTTAsync_waitForCompletion(MQTTAsync handle, MQTTAsync_token token, unsigned long timeout)
DLLExport int MQTTAsync_subscribe(MQTTAsync handle, const char *topic, int qos, MQTTAsync_responseOptions *response)
void MQTTAsync_onSuccess(void *context, MQTTAsync_successData *response)
Definition: MQTTAsync.h:431
int MQTTAsync_token
Definition: MQTTAsync.h:234
DLLExport int MQTTAsync_isConnected(MQTTAsync handle)
DLLExport int MQTTAsync_unsubscribe(MQTTAsync handle, const char *topic, MQTTAsync_responseOptions *response)
DLLExport void MQTTAsync_free(void *ptr)
DLLExport int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions *options)
DLLExport void MQTTAsync_setTraceCallback(MQTTAsync_traceCallback *callback)
void MQTTAsync_deliveryComplete(void *context, MQTTAsync_token token)
Definition: MQTTAsync.h:346
DLLExport int MQTTAsync_unsubscribeMany(MQTTAsync handle, int count, char *const *topic, MQTTAsync_responseOptions *response)
DLLExport int MQTTAsync_sendMessage(MQTTAsync handle, const char *destinationName, const MQTTAsync_message *msg, MQTTAsync_responseOptions *response)
DLLExport int MQTTAsync_subscribeMany(MQTTAsync handle, int count, char *const *topic, int *qos, MQTTAsync_responseOptions *response)
DLLExport int MQTTAsync_setConnected(MQTTAsync handle, void *context, MQTTAsync_connected *co)
DLLExport void MQTTAsync_destroy(MQTTAsync *handle)
DLLExport void MQTTAsync_setTraceLevel(enum MQTTASYNC_TRACE_LEVELS level)
DLLExport MQTTAsync_nameValue * MQTTAsync_getVersionInfo(void)
This structure represents a persistent data store, used to store outbound and inbound messages,...
Definition: MQTTAsync.h:661
const char * trustStore
Definition: MQTTAsync.h:668
int struct_version
Definition: MQTTAsync.h:665
const char * CApath
Definition: MQTTAsync.h:713
const char * keyStore
Definition: MQTTAsync.h:673
int sslVersion
Definition: MQTTAsync.h:699
int enableServerCertAuth
Definition: MQTTAsync.h:693
const char * privateKey
Definition: MQTTAsync.h:678
int verify
Definition: MQTTAsync.h:706
const char * enabledCipherSuites
Definition: MQTTAsync.h:690
const char * privateKeyPassword
Definition: MQTTAsync.h:680
Definition: MQTTAsync.h:724
int maxRetryInterval
Definition: MQTTAsync.h:852
int cleansession
Definition: MQTTAsync.h:767
int struct_version
Definition: MQTTAsync.h:734
MQTTAsync_onFailure * onFailure
Definition: MQTTAsync.h:814
const void * data
Definition: MQTTAsync.h:858
int MQTTVersion
Definition: MQTTAsync.h:840
int minRetryInterval
Definition: MQTTAsync.h:848
int connectTimeout
Definition: MQTTAsync.h:793
int maxInflight
Definition: MQTTAsync.h:771
int automaticReconnect
Definition: MQTTAsync.h:844
MQTTAsync_willOptions * will
Definition: MQTTAsync.h:777
MQTTAsync_SSLOptions * ssl
Definition: MQTTAsync.h:802
const char * password
Definition: MQTTAsync.h:789
int serverURIcount
Definition: MQTTAsync.h:824
char *const * serverURIs
Definition: MQTTAsync.h:833
const char * username
Definition: MQTTAsync.h:783
MQTTAsync_onSuccess * onSuccess
Definition: MQTTAsync.h:808
int retryInterval
Definition: MQTTAsync.h:797
int keepAliveInterval
Definition: MQTTAsync.h:745
void * context
Definition: MQTTAsync.h:820
int len
Definition: MQTTAsync.h:857
Definition: MQTTAsync.h:583
int struct_version
Definition: MQTTAsync.h:587
int sendWhileDisconnected
Definition: MQTTAsync.h:589
int maxBufferedMessages
Definition: MQTTAsync.h:591
Definition: MQTTAsync.h:890
int struct_version
Definition: MQTTAsync.h:894
MQTTAsync_onFailure * onFailure
Definition: MQTTAsync.h:911
int timeout
Definition: MQTTAsync.h:899
MQTTAsync_onSuccess * onSuccess
Definition: MQTTAsync.h:905
void * context
Definition: MQTTAsync.h:917
Definition: MQTTAsync.h:384
const char * message
Definition: MQTTAsync.h:390
int code
Definition: MQTTAsync.h:388
MQTTAsync_token token
Definition: MQTTAsync.h:386
Definition: MQTTAsync.h:203
int struct_version
Definition: MQTTAsync.h:207
int do_openssl_init
Definition: MQTTAsync.h:209
Definition: MQTTAsync.h:243
int struct_version
Definition: MQTTAsync.h:247
int qos
Definition: MQTTAsync.h:265
int msgid
Definition: MQTTAsync.h:295
int retained
Definition: MQTTAsync.h:284
void * payload
Definition: MQTTAsync.h:251
int payloadlen
Definition: MQTTAsync.h:249
int dup
Definition: MQTTAsync.h:291
Definition: MQTTAsync.h:1177
const char * value
Definition: MQTTAsync.h:1179
const char * name
Definition: MQTTAsync.h:1178
Definition: MQTTAsync.h:446
int struct_version
Definition: MQTTAsync.h:450
MQTTAsync_onFailure * onFailure
Definition: MQTTAsync.h:462
MQTTAsync_onSuccess * onSuccess
Definition: MQTTAsync.h:456
void * context
Definition: MQTTAsync.h:468
MQTTAsync_token token
Definition: MQTTAsync.h:474
Definition: MQTTAsync.h:395
int MQTTVersion
Definition: MQTTAsync.h:415
int qos
Definition: MQTTAsync.h:402
int sessionPresent
Definition: MQTTAsync.h:416
MQTTAsync_message message
Definition: MQTTAsync.h:408
int * qosList
Definition: MQTTAsync.h:404
char * serverURI
Definition: MQTTAsync.h:414
char * destinationName
Definition: MQTTAsync.h:409
MQTTAsync_token token
Definition: MQTTAsync.h:397
Definition: MQTTAsync.h:613
int struct_version
Definition: MQTTAsync.h:619
const void * data
Definition: MQTTAsync.h:637
const char * topicName
Definition: MQTTAsync.h:621
const char * message
Definition: MQTTAsync.h:623
int qos
Definition: MQTTAsync.h:632
int retained
Definition: MQTTAsync.h:627
int len
Definition: MQTTAsync.h:636